package com.dyz.leetcode._01_array;

public class _125_isPalindrome {
    public boolean isPalindrome(String s) {
        int n = s.length();
        if(n<=1){return true;}
        int left = 0;
        int right = n-1;
        while(left<right){
            //判断左边是否为为数字或者字符
            while (left<right && !Character.isLetterOrDigit(s.charAt(left))){
                left++;
            }
            //判断右边是否为为数字或者字符
            while(left<right && !Character.isLetterOrDigit(s.charAt(right))){
                right--;
            }

            if(Character.toLowerCase(s.charAt(left))!=Character.toLowerCase(s.charAt(right))){
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
}
